#include <iostream>
//#include <string>
using namespace std;



int main()
{
	string tmp1 = "", tmp2 = "", tmp3 = "";
	for (int i = 0; i < 101; i++)
		tmp2 += 'a';
	char c;
	while ((c = getchar()) != EOF) {
		if (!isalpha(c)) {
			if (tmp3 != "") {
				if (tmp1.size() <= tmp3.size())
					tmp1 = tmp3;
				if (tmp2.size() >= tmp3.size())
					tmp2 = tmp3;
				tmp3 = "";
			}
		}
		else {
			tmp3 += c;
		}
	}
	if (tmp3 != "") {
		if (tmp1.size() <= tmp3.size())
			tmp1 = tmp3;
		if (tmp2.size() >= tmp3.size())
			tmp2 = tmp3;
	}
	cout << tmp1 << endl << tmp2;
	return 0;
}